package com.lancoo.znbkxx.teacher.ui.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.Gravity
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.bumptech.glide.Glide
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkTestCoach.aibkTools.LancooMethod
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.ClassStuCognitiveHonorRollListInfor
import com.lancoo.znbkxx.teacher.ui.adapter.AibkClassStuHonorRollListAdapter
import kotlinx.android.synthetic.main.aibk_dialog_student_cognitive_honor_roll_list.*
import kotlinx.android.synthetic.main.aibk_include_honor_roll_student_top3.*


class DialogCognitiveHonorRollList(
        context: Context?,
        val classStuCognitiveHonorRollListInfor: ClassStuCognitiveHonorRollListInfor
) : Dialog(context!!, R.style.CustomDialog) {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.aibk_dialog_student_cognitive_honor_roll_list)
        window!!.setGravity(Gravity.BOTTOM) //设置弹窗右对齐
        window!!.setWindowAnimations(R.style.MyDialogBottomTranslate) //设置动画效果

        val wl = window!!.attributes
        //以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        onWindowAttributesChanged(wl)
        setCanceledOnTouchOutside(true)

        //初始化界面数据
        initView()
    }

    /**
     * 初始化界面控件的显示数据
     */
    private fun initView() {

        //关闭dialog
        IvCloseDialog.setOnClickListener {
            dismiss()
        }

        val stuName1 = classStuCognitiveHonorRollListInfor!!.ClassIndexInfoList[0].StuName
        val stuName2 = classStuCognitiveHonorRollListInfor!!.ClassIndexInfoList[1].StuName
        val stuName3 = classStuCognitiveHonorRollListInfor!!.ClassIndexInfoList[2].StuName
        val stuScore1 = classStuCognitiveHonorRollListInfor!!.ClassIndexInfoList[0].StuScore
        val stuScore2 = classStuCognitiveHonorRollListInfor!!.ClassIndexInfoList[1].StuScore
        val stuScore3 = classStuCognitiveHonorRollListInfor!!.ClassIndexInfoList[2].StuScore
        val stuPhotoPath1 = classStuCognitiveHonorRollListInfor!!.ClassIndexInfoList[0].StuPhotoPath
        val stuPhotoPath2 = classStuCognitiveHonorRollListInfor!!.ClassIndexInfoList[1].StuPhotoPath
        val stuPhotoPath3 = classStuCognitiveHonorRollListInfor!!.ClassIndexInfoList[2].StuPhotoPath
        val cognitiveGradeName1 = classStuCognitiveHonorRollListInfor!!.ClassIndexInfoList[0].CognitiveGradeName
        val cognitiveGradeName2 = classStuCognitiveHonorRollListInfor!!.ClassIndexInfoList[1].CognitiveGradeName
        val cognitiveGradeName3 = classStuCognitiveHonorRollListInfor!!.ClassIndexInfoList[2].CognitiveGradeName

        TvNameTopOne.text = stuName1
        TvNameTopTwo.text = stuName2
        TvNameTopThree.text = stuName3
        TvScoreTopOne.text = LancooMethod.killlingDouble(stuScore1)
        TvScoreTopTwo.text = LancooMethod.killlingDouble(stuScore2)
        TvScoreTopThree.text = LancooMethod.killlingDouble(stuScore3)
        Glide.with(context).load(stuPhotoPath1).into(CivHeadTopOne);
        Glide.with(context).load(stuPhotoPath2).into(CivHeadTopTwo);
        Glide.with(context).load(stuPhotoPath3).into(CivHeadTopThree);
        TvTitlesTopOne.text = cognitiveGradeName1
        TvTitlesTopTwo.text = cognitiveGradeName2
        TvTitlesTopThree.text = cognitiveGradeName3


        val manager = LinearLayoutManager(context)
        manager.orientation = LinearLayoutManager.VERTICAL
        RvStuHonorRollList.layoutManager = manager
        val mAdapter = AibkClassStuHonorRollListAdapter(context, classStuCognitiveHonorRollListInfor)
        RvStuHonorRollList.adapter = mAdapter
    }

}